<!DOCTYPE html>
<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>账套管理</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/public.css">
<script type="text/javascript" src="${contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/common.js"></script>
</head>
<body>
	<%@ include file="../nav.jsp"%>
	<div class="container">
		<div class="panel panel-default">
			<div class="panel-heading">账套管理(注：需要配合acc.bat文件的命令行！)</div>
			<div class="panel-body">
			<div>
			<a href="javascript:ct('${contextPath}/security/clearTable?t=customer')">清空客户</a>
			<a href="javascript:ct('${contextPath}/security/clearTable?t=orders')">清空订单</a>
			<a href="javascript:ct('${contextPath}/security/clearTable?t=product')">清空产品</a>
			<a href="javascript:ct('${contextPath}/security/clearTable?t=code')">清空选项</a>
			</div>
			<div>
				<label for="dbs">查看历史账套</label>
				<select id="dbs">
				</select>
				<button onclick="ipt()" type="button">查看账套</button>
			</div>
			<div>

				<label for="y">输入导出账套年</label>
				<input type="text" id="y" name="y" placeholder="输入导出账套年"></input>
				<button onclick="ept()" type="button">导出账套</button>
				<span>例如导出2019年的账套,输入2019即可</span>
			</div>
			<p>
			注意事项：导出账套前需备份当前数据库文件，并将改文件永久保存。<br/>
			导出账套的主要操作：<br/>
			1.复制tomcat/webapps/crm文件夹，更名为导出账套年份的项目 例如：tomcat/webapps/crm2019<br/>
			2.修改webapps\crm2019\WEB-INF\classes\application.properties文件的<br/>
			<abbr>spring.datasource.url=jdbc:mysql://127.0.0.1:3306/crm2019?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false></abbr><br/>
			
			3.
			</p>
</div>
		</div>

	</div>

<%--loading遮罩层--%>
<div class="modal fade" id="loadingModal" backdrop="static" keyboard="false">
    　　<div style="width: 600px;height:20px; z-index: 20000; position: absolute; text-align: center; left: 30%; top: 50%;margin-left:-100px;margin-top:-10px">
    　　　　<div class="progress progress-striped active" style="margin-bottom: 0;">
    　　　　　　<div class="progress-bar" style="width: 100%;"></div>
    　　　　</div>
    　　　　<h4 id="loadText" style="font-weight: bold; color: white;" >重要提示:正在进行重要处理请耐心等待，不要进行任何其他操作！！！</h4>
    　　</div>
</div>

	<script type="text/javascript">
	var timer1=null;
    var loadingTime= 0;//默认遮罩时间
    
    showLoading = function (loadText) {
        if(!loadText){
            $("#loadText").html(loadText)
        }
        $('#loadingModal').modal({backdrop: 'static', keyboard: false});
    }
    hideLoading = function () {
        $('#loadingModal').modal('hide');
    }
	
		$(document).ready(function() {
			dbs();
		})
		dbs = function() {
			$("#dbs").empty();
			$.ajax({
				type : 'GET',
				url : '${contextPath}/security/getDatabases',
				data : {},
				dataType : 'json',
				success : function(data) {
					$.each(data.list, function(i, item) {
						$("#dbs").append("<option>" + item.replace('crm','') + "</option>");
					});
				}
			});
		};
		ipt = function() {
			var h = $("#dbs").val();
			showLoading();
			//$(".progress-bar").css("width",loadingTime+"%");
			//$(".progress-bar").css("width",loadingTime+"%");
		    //timer1=window.setInterval(function(){
		    	//loadingTime+=5;
		    	//$(".progress-bar").css("width",loadingTime+"%");
		    //},1000);
		    //var n=h.replace('crm','');
		    window.top.document.location.href="${contextPath}"+h+"/login"
		    /**
			$.ajax({
				type : 'POST',
				async : true,
				url : '${contextPath}/security//import',
				data : {
					"h" : h
				},
				dataType : 'json',
				success : function(data) {
					hideLoading();
					loadingTime=0;
					timer1=null;
					if (data.exitValue == 0) {
						dbs();
						$(".progress-bar").css("width","100%");
						window.clearInterval(timer1); 
						alert("导入账套成功！");
					} else {
						alert("导入账套失败！");
					}
				}
			});
		    **/
		}
		
		ept = function() {
			var y = $("#y").val();
			if (y == "") {
				alert("年份不能为空");
				return;
			}
			showLoading();
			$(".progress-bar").css("width",loadingTime+"%");
		    timer1=window.setInterval(function(){
		    	loadingTime+=5;
		    	$(".progress-bar").css("width",loadingTime+"%");
		    },1000);
			$.ajax({
				type : 'POST',
				async : true,
				url : '${contextPath}/security/export',
				data : {
					"y" : y
				},
				dataType : 'json',
				success : function(data) {
					hideLoading();
					loadingTime=0;
					timer1=null;
					if (data.exitValue == 0) {
						dbs();
						$(".progress-bar").css("width","100%");
						window.clearInterval(timer1); 
						alert("导出账套成功！");
					} else {
						alert("导出账套失败！");
					}
					
				}
			});
		}
		var ct = function(t){
			if(confirm('确定要清空吗？')==true){
			 	$.get(t, function(result){
			 		alert("清空完成");
				})
				return true;
			}
			return false;
		}
	</script>


</body>

</html>
